#!/bin/bash

# 查看各个文件中的字段数
# yzhaozilong v1.0
# yzhaozilong v1.1 增加查看文件里面有那些不同的列,date:2013-07-28 23:01

E_WRONGARGS=65

if [ ! -d "$1" ]
then
   echo "$1 is not directory!"
   exit $E_WRONGARGS
fi

temp=$2
if [ ${#temp} != 1 ]
then
   echo "second arg length don't with one"
   exit $E_WRONGARGS
fi

case "$2" in
[[:punct:]]  ) ;;
*            ) echo "second arg with punctuation symbol"; exit $E_WRONGARGS;;
esac

for file in $(find $1 -type f)
do
   #string=`sed -n '1p' $file | awk 'BEGIN {FS="'$2'"} {print "column: "NF}'`
   string=(`cat $file | awk 'BEGIN {FS="'$2'"} {print NR"row,column:"NF";"}'|sort -u -t "," -k 2`)
   #echo ${string[@]}
   echo "$file==>${string[@]}"
  
done
